package com.study.talk.ui.app.home.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.study.talk.ui.adapter.UsersAdapter
import com.study.talk.ui.app.base.BaseFragment
import com.study.talk.databinding.FragmentFriendBinding

class FriendFragment : BaseFragment() {

    private val adapter: UsersAdapter by lazy { UsersAdapter(UsersAdapter.CHAT) }
    private lateinit var binding: FragmentFriendBinding

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
    ): View {
        binding = FragmentFriendBinding.inflate(inflater, container, false)
        binding.fragmentFriendListView.adapter = adapter
        binding.fragmentFriendListView.layoutManager = LinearLayoutManager(requireContext())
        app.friends.observe(viewLifecycleOwner) {
            if (it.isEmpty()){
                binding.fragmentFriendListView.visibility = View.GONE
                binding.fragmentFriendEmptyView.visibility = View.VISIBLE
            }else{
                binding.fragmentFriendListView.visibility = View.VISIBLE
                binding.fragmentFriendEmptyView.visibility = View.GONE
                adapter.submitList(it)
            }
        }
        return binding.root
    }
}